package cc.autoapi.pucong.auto.flow.provider.log.controller;

import cc.autoapi.pucong.auto.flow.core.root.entity.BatchDeleteIdDto;
import cc.autoapi.pucong.auto.flow.core.root.exception.AutoFlowBaseController;
import cc.autoapi.pucong.auto.flow.core.root.exception.AutoFlowExceptionHandler;
import cc.autoapi.pucong.auto.flow.core.root.utils.Res;
import cc.autoapi.pucong.auto.flow.persistence.utils.jdbc.BasePageVo;
import cc.autoapi.pucong.auto.flow.provider.log.manager.ApiInstanceManager;
import cc.autoapi.pucong.auto.flow.provider.log.entity.qo.ApiInstanceQo;
import cc.autoapi.pucong.auto.flow.provider.log.entity.vo.ApiInstanceDetailVo;
import cc.autoapi.pucong.auto.flow.provider.log.entity.vo.ApiInstanceVo;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author pucong
 * @description 项目api实例 controller
 * @create 2024-10-07
 */
@RestController
@Validated
@RequestMapping("/log/apiInstance")
public class ApiInstanceController extends AutoFlowBaseController implements AutoFlowExceptionHandler{

    @Resource
    private ApiInstanceManager apiInstanceManager;

    @GetMapping("/queryByPage/{pageNum}/{pageSize}")
    public Res<BasePageVo<ApiInstanceVo>> queryByPage(@PathVariable("pageNum") int pageNum,
                                                      @PathVariable("pageSize") int pageSize,
                                                      ApiInstanceQo qo) {
        BasePageVo<ApiInstanceVo> apiInstancePageList = apiInstanceManager.queryByPage(pageNum, pageSize, qo);
        return Res.ok(apiInstancePageList);
    }

    @GetMapping("/getDetailById/{id}")
    public Res<ApiInstanceDetailVo> getDetailById(@PathVariable("id") String id) {
        ApiInstanceDetailVo apiInstanceDto = apiInstanceManager.getDetailById(id);
        return Res.ok(apiInstanceDto);
    }

    @DeleteMapping("/batchDeleteByIds")
    public Res<Boolean> batchDeleteByIds(BatchDeleteIdDto dto) {
        Boolean i = apiInstanceManager.batchDeleteByIds(dto.getIdList());
        return Res.ok(i);
    }
}
